這篇文章要介紹,如何使用 HTML 和 CSS 創建一個具有 3D 立體效果的加載動畫
創建一個 loading-container
容器,裡面包含加載的文字效果
<div class="loading-container">
<h1 class="loading-text">
<span>L</span>
<span>o</span>
<span>a</span>
<span>d</span>
<span>i</span>
<span>n</span>
<span>g</span>
<span>...</span>
</h1>
</div>
h1
標籤可以幫助強調這段文本的重要性span
標籤包裹,可以讓每個字母或動畫進行單獨設計使用 Flexbox
將頁面內容居中顯示,確保文字位於畫面正中間
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background: #808069;
}
.loading-container {
perspective: 800px;
}
.loading-text {
font-size: 100px;
}
.loading-text span {
display: inline-block;
color: rgba(255, 255, 255, 0.8);
text-shadow: -1px -1px rgba(255, 223, 140, 0.8),
-2px -2px rgba(255, 223, 140, 0.8),
-3px -3px rgba(255, 223, 140, 0.8),
-4px -4px rgba(255, 223, 140, 0.8),
-5px -5px rgba(255, 223, 140, 0.8),
-6px -6px rgba(255, 223, 140, 0.8);
animation: float 2s ease-in-out infinite;
}
@keyframes float {
0% {
transform: translateY(0);
}
50% {
transform: translateY(-20px); /
}
100% {
transform: translateY(0);
}
}
.loading-text span:nth-child(1) { animation-delay: 0s; }
.loading-text span:nth-child(2) { animation-delay: 0.1s; }
.loading-text span:nth-child(3) { animation-delay: 0.2s; }
.loading-text span:nth-child(4) { animation-delay: 0.3s; }
.loading-text span:nth-child(5) { animation-delay: 0.4s; }
.loading-text span:nth-child(6) { animation-delay: 0.5s; }
.loading-text span:nth-child(7) { animation-delay: 0.6s; }
.loading-text span:nth-child(8) { animation-delay: 0.7s; }
span
元素。span
子元素